package com.ews.onlineexchange.model;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

@Embeddable
public class Business implements Serializable {
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	private AgentService		agentService;
	private String				agentServiceDetail;
	private String				commitOfTime;
	private String				commitOfPrice;
	private String				commitOfQuality;
	private String				bussinessIndex;

	@ManyToOne
	public AgentService getAgentService() {
		return agentService;
	}

	public void setAgentService( AgentService agentService ) {
		this.agentService = agentService;
	}

	@Length( max = 2000 )
	public String getAgentServiceDetail() {
		return agentServiceDetail;
	}

	public void setAgentServiceDetail( String agentServiceDetail ) {
		this.agentServiceDetail = agentServiceDetail;
	}

	@NotNull
	public String getCommitOfTime() {
		return commitOfTime;
	}

	public void setCommitOfTime( String commitOfTime ) {
		this.commitOfTime = commitOfTime;
	}

	@Transient
	public String getBussinessIndex() {
		return bussinessIndex;
	}

	public void setBussinessIndex( String bussinessIndex ) {
		this.bussinessIndex = bussinessIndex;
	}

	@NotNull
	public String getCommitOfPrice() {
		return commitOfPrice;
	}

	public void setCommitOfPrice( String commitOfPrice ) {
		this.commitOfPrice = commitOfPrice;
	}

	@NotNull
	public String getCommitOfQuality() {
		return commitOfQuality;
	}

	public void setCommitOfQuality( String commitOfQuality ) {
		this.commitOfQuality = commitOfQuality;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((agentService == null) ? 0 : agentService.hashCode());
		result = prime * result + ((agentServiceDetail == null) ? 0 : agentServiceDetail.hashCode());
		result = prime * result + ((bussinessIndex == null) ? 0 : bussinessIndex.hashCode());
		result = prime * result + ((commitOfPrice == null) ? 0 : commitOfPrice.hashCode());
		result = prime * result + ((commitOfQuality == null) ? 0 : commitOfQuality.hashCode());
		result = prime * result + ((commitOfTime == null) ? 0 : commitOfTime.hashCode());
		return result;
	}

	@Override
	public boolean equals( Object obj ) {
		if ( this == obj )
			return true;
		if ( obj == null )
			return false;
		if ( getClass() != obj.getClass() )
			return false;
		Business other = (Business) obj;
		if ( agentService == null ) {
			if ( other.agentService != null )
				return false;
		} else if ( !agentService.equals( other.agentService ) )
			return false;
		if ( agentServiceDetail == null ) {
			if ( other.agentServiceDetail != null )
				return false;
		} else if ( !agentServiceDetail.equals( other.agentServiceDetail ) )
			return false;
		if ( bussinessIndex != other.bussinessIndex )
			return false;
		if ( commitOfPrice == null ) {
			if ( other.commitOfPrice != null )
				return false;
		} else if ( !commitOfPrice.equals( other.commitOfPrice ) )
			return false;
		if ( commitOfQuality == null ) {
			if ( other.commitOfQuality != null )
				return false;
		} else if ( !commitOfQuality.equals( other.commitOfQuality ) )
			return false;
		if ( commitOfTime == null ) {
			if ( other.commitOfTime != null )
				return false;
		} else if ( !commitOfTime.equals( other.commitOfTime ) )
			return false;
		return true;
	}

	@Transient
	public String getAgentServiceName() {
		if ( null == getAgentService() )
			return "";
		else
			return getAgentService().getName();
	}

}
